<template>
	<!--企业基本信息-->
	<view class="padding-bottom-lg">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">
				<view class="custom-title">企业信息</view>
			</block>
		</cu-custom>
		<view class="progress1 padding-top-32">
			<view class="progress-circle-1">
				<view class="complate-content">
					<image src="https://txr001.zthj.net/static/img/complate.png" class="img-40"></image>
				</view>
				<text class="progress-text">工商信息</text>
			</view>
			<view class="progress-line1"></view>
			<view class="progress-circle-gray">
				<view class="complate-content">
					<view class="uncomplate-content"></view>
				</view>
				<text class="progress-text text-767879">联系信息</text>
			</view>
		</view>
		<view class="margin-32 padding-32 bg-white radius-48">
			<form @submit="toSubmit">
				<view class="basic-qy-name">法人代表姓名：</view>
				<input class="basic-qy-input" placeholder="请输入法人代表姓名：" v-model="leader" name="input"></input>

				<view class="basic-qy-name padding-top-48">法人代表联系地址：</view>
				<input class="basic-qy-input" placeholder="请输入法人代表联系地址" v-model="address" name="input"></input>

				<view class="basic-qy-name padding-top-48">法人身份证明类型：</view>
				<radio-group class="block " @change="idchange">
					<view class="padding-top-lg padding-bottom">
						<view class="flex align-start">
							<view class="flex-sub flex align-center justify-start">
								<radio value="1" :checked="id_type==1" style="transform:scale(0.8)"></radio>
								<text class="basic-radio-title-two">身份证</text>
							</view>
							<view class="flex-sub flex align-start justify-start">
								<radio value="2" :checked="id_type==2" style="transform:scale(0.8)"></radio>
								<text class="basic-radio-title-two margin-top-6">港澳居民来往内地通行证</text>
							</view>
						</view>
						<view class="flex padding-top-40">
							<view class="flex-sub flex align-start justify-start">
								<radio value="3" :checked="id_type==3" style="transform:scale(0.8)"></radio>
								<text class="basic-radio-title-two margin-top-6">台湾居民来往大陆通行证</text>
							</view>
							<view class="flex-sub flex align-start justify-start">
								<radio value="4" :checked="id_type==4" style="transform:scale(0.8)"></radio>
								<text class="basic-radio-title-two margin-top-6">护照或外国人永久居留证</text>
							</view>
						</view>
					</view>
				</radio-group>

				<view class="basic-qy-name padding-top-80">证件号码：</view>
				<input class="basic-qy-input" placeholder="请输入证件号码" v-model="idnumber" name="input"></input>

				<view class="basic-qy-name padding-top-48">认证地区：</view>
				<view class="cu-form-group">
					<picker mode="selector" @change="bindPickerChange" :value="index" :range="list">
						<view class="picker">
							{{list[index]}}
						</view>
					</picker>
				</view>

				<view class="basic-update-title padding-top-48 flex justify-between align-center">
					<view class="text-bold">委托授权书（盖章）：</view>
					<view @click="fileUpload">
						<image src="https://txr001.zthj.net/static/khxz.png" class="basic-title-img"></image>
						<text class="wtsqs-class">委托授权书</text>
					</view>
				</view>
				<view @click="ChooseImage(1)" class="yyzz-content flex align-center justify-center">
					<view class="sqs flex align-center justify-center"
						:style="{backgroundImage:`url(${shouquan_url})`}">
						<view class="camera-content flex align-center justify-center">
							<image src="https://txr001.zthj.net/static/camera.png" class="camara-img"></image>
						</view>
					</view>
				</view>
				<view class="padding-top-32 update-info">
					注:1.请下载委托授权书根据要求填写然后加盖企业公章
					<view class="padding-left">2.JPG或PNG格式，大小不超过5MB，拍摄时确保内容完整,字体清晰,亮度均匀；</view>
				</view>

				<view class="basic-qy-name padding-top-48">联系人/被授权人手机：</view>
				<input class="basic-qy-input margin-top" v-model="mobile" placeholder="请输入手机号"></input>

				<view class="basic-qy-name padding-top-48">联系人/被授权人邮箱：</view>
				<input class="basic-qy-input" v-model="email" placeholder="请输入邮箱"></input>

				<view class="basic-qy-name padding-top-48">logo：</view>
				<view class="file-up-content margin-top-12" @click="ChooseImage(2)">
					<image :src="logo" class="img-80"></image>
				</view>
				<view class="padding-top-32 update-info">
					注:1.JPG或PNG格式，大小不超过5MB，
					<view class="padding-left">2.建议尺寸:200*200</view>
				</view>
				<view class="padding flex align-center justify-center">
					<button class="cu-btn round submit-btn" form-type="submit">提交信息</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				leader: '',
				address: '',
				id_type: 1,
				idnumber: '',
				region: '中国大陆',
				mobile: '',
				email: '',
				shouquan_url: '',
				index: 0,
				list: ['中国大陆'],
				logo: '',
				id: 0
			}
		},
		onLoad(e) {
			this.getInfo();
			// if (e.id) {
			// 	this.id = e.id;
			// 	this.isUpdate = true;

			// }
		},
		methods: {
			postImg(imgFilePaths, type) {
				uni.uploadFile({
					url: 'https://qd.zthj.net/api/Common/upload',
					filePath: imgFilePaths,
					name: 'file',
					success: (res) => {
						let info = JSON.parse(res.data)
						// console.log(res.data);
						if (type == 1) {
							this.shouquan_url = info.data.fullurl;
						} else {
							this.logo = info.data.fullurl;
						}

					}
				});
			},
			ChooseImage(type) {
				let that = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						// console.log();
						that.postImg(res.tempFilePaths[0], type)
					}
				});
			},
			async toSubmit() {
				if (!this.leader) {
					uni.showToast({
						title: '请输入法人代表姓名',
						icon: 'none'
					})
					return
				}
				if (!this.address) {
					uni.showToast({
						title: '请输入法人代表联系地址',
						icon: 'none'
					})
					return
				}
				if (!this.idnumber) {
					uni.showToast({
						title: '请输入证件号码',
						icon: 'none'
					})
					return
				}

				if (this.shouquan_url == 'https://txr001.zthj.net/static/sqs.png') {
					uni.showToast({
						title: '请上传授权书',
						icon: 'none'
					})
					return
				}
				if (this.logo == 'https://txr001.zthj.net/static/img/fileUpload.png') {
					uni.showToast({
						title: '请上传logo',
						icon: 'none'
					})
					return
				}
				let mobilereg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
				if (!this.mobile) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				} else if (!mobilereg.test(this.mobile)) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					})
					return
				}
				let email_reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
				if (!this.email) {
					uni.showToast({
						title: '请输入邮箱',
						icon: 'none'
					})
					return
				} else if (!email_reg.test(this.email)) {
					uni.showToast({
						title: '请输入正确的邮箱',
						icon: 'none'
					})
					return
				}
				let res = await this.$api.updateContact({
					leader: this.leader,
					address: this.address,
					id_type: this.id_type,
					idnumber: this.idnumber,
					region: this.region,
					mobile: this.mobile,
					email: this.email,
					shouquan_url: this.shouquan_url,
					logo: this.logo,
					id: this.id
				});
				if (res.code == 1) {
					uni.navigateTo({
						url: "/subpackage/pages/mine/company/success?type=1"
					})
				} else {
					uni.showToast({
						title: '提交信息失败！',
						icon: 'none'
					})
				}
			},
			idchange(e) {
				this.id_type = e.detail.value;
			},
			getInfo: async function() {
				let res = await this.$api.basicdetail();
				this.leader = res.leader ? res.address : '';
				this.address = res.address ? res.address : '';
				this.id_type = res.id_type ? res.id_type : 1;
				this.idnumber = res.leader_idcard ? res.leader_idcard : '';
				this.region = res.region ? res.region : '中国大陆';
				this.mobile = res.mobile ? res.mobile : '';
				this.email = res.email ? res.email : '';
				this.shouquan_url = res.shouquan_url ? res.shouquan_url : "https://txr001.zthj.net/static/sqs.png";
				this.logo = res.logo ? res.logo : "https://txr001.zthj.net/static/img/fileUpload.png";
				this.id = res.id;

			},
			bindPickerChange(e) {
				this.index = e.detail.value
				this.region = this.list[e.detail.value];
			},
			// 下载文件
			fileUpload() {
				window.open(
					"https://txr001.zthj.net/asd.pdf"
				)
			}
		}
	}
</script>
<style scoped>
	.uni-radio-input {
		background: #24458E !important;
		border-color: #24458E !important;
	}

	.uni-radio-input-checked {
		background: #24458E !important;
		border-color: #24458E !important;
	}

	input {
		color: black;
	}

	.progress-line1 {
		width: 286rpx !important;
	}
</style>